package br.jm.i18n;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class ResourceBundleMessageProvider implements MessageProvider {

	final String resourceLoc;

	public ResourceBundleMessageProvider(final Class<?> clazz, final Locale loc) {
		this.resourceLoc = clazz.getName();
	}

	@Override
	public String getMessage(final String key, final Locale loc) {
		try {
			final String val = ResourceBundle.getBundle(resourceLoc, loc).getString(key);
			return val;
		} catch (final MissingResourceException ex) {
			return MessageFormat.format("Requires bundle/key for {0} in scope {1}", key, resourceLoc);
		}
	}
}
